home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7322 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  44 lines

  1. Path: news.Gsu.EDU!gs01lmh
  2. From: gs01lmh@panther.Gsu.EDU (Louis Miller Hall)
  3. Newsgroups: comp.lang.c++
  4. Subject: Need some simple help with C++
  5. Date: 22 Feb 1996 17:10:12 GMT
  6. Organization: Georgia State University
  7. Message-ID: <4gi81k$ebb@sphinx.Gsu.EDU>
  8. NNTP-Posting-Host: panther.gsu.edu
  9. NNTP-Posting-User: gs01lmh
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. I am having a problem getting the following code to reuse a string so 
  13. that I can put and print various info into it, when the program runs, it 
  14. will successfully output the data the first time through the loop, but 
  15. after that, it will continue to run, but not allow you to enter another 
  16. string, and moreover outputs an empty string??!!!? Can anybody tell me 
  17. what I am doing wrong:
  18.  
  19. #include <fstream.h>
  20.  
  21. char *name;
  22. int  a = 1;
  23.  
  24. void main ()
  25.   {
  26.   while (a)
  27.     {
  28.     name = new char[80];
  29.     cout << "What is the string >" << endl;
  30.     cin.getline(name, 80);
  31.     cout << "The string entered is >" << name << endl;
  32.     cout << "Enter 0 to quit, any other to continue>";
  33.     cin >> a;
  34.     delete name;  // will work the same with or without this
  35.     }  // while
  36.   }  // main
  37.  
  38. I have also tried using char name[80]; but this too fails, I am trying to 
  39. teach myself C++, and any addtional help I could get would be 
  40. appreciated.  
  41.  
  42. Thanks
  43.  
  44.